package businessServlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;

import controller.Controller;
import dataBase.Business;


@SuppressWarnings("serial")
public class DeleteAdBusiness extends HttpServlet {
		
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		System.out.println("delete ad");
		String bizUserName=(String) req.getSession().getAttribute("userNameBusiness");
		String idString=req.getParameter("id"); 
		
		try
    	{
    		int id = Integer.parseInt(idString);
    		int result = Controller.getInstance().deleteAdBusiness(bizUserName,id);
    		
    		switch(result)
    		{
    		case 0:
    			resp.sendRedirect("myProfileBusiness2.jsp#advertisement");
    			break;
    		case 1:
    			System.out.println("1- no such biz");
    			resp.sendRedirect("home.jsp");
    			break; 
    		case 2:
    			System.out.println("2 - no such ad");
    			resp.sendRedirect("home.jsp");
    			break;
    		}
    	} catch(NumberFormatException e) {
    		System.out.println("ad id isn't a number");
    		
    	}


	}
	
}
